import httpInstance from '@/utils/http'
// 加入购物车
export const insertCartAPI = async ({ productId, quantity }) => {
  try {
    const res = await httpInstance.request({
      url: '/api/cart/add',
      method: 'POST',
      data: {
        productId,
        quantity
      }
    })
    return res
  } catch (error) {
    throw error
  }
  }

  // 获取最新购物车列表
  export async function getCartListAPI() {
    try{
      const res = await httpInstance.request({
        url: '/api/cart/list',
        method: 'GET',
    })
    return res
    }catch(err){
      console.log(err)
      throw err;
    }
  }


  // 删除购物车
  export async function deleteCartAPI(skuId) {
    try{
      const res = await httpInstance.request({
        url: `/api/cart/${skuId}`,
        method: 'DELETE',
      })
      return res.data
    }catch(err){
      console.log(err)
      throw err;
  }
  }


  // 清空购物车
export async function clearCartAPI() {
  try{
    const res = await httpInstance.request({
      url: '/api/cart/clear',
      method: 'DELETE',
    })
    return res.data
  }catch(err){
    console.log(err)
    throw err;
  }
}
